﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace Domain
{
    /// <summary>
    /// Результат участника в одном заезде
    /// </summary>
    public class RunResult: INotifyPropertyChanged
    {
        #region Fields
        
        private TimeSpan? _time;

        private RunResultType _resultType;

        #endregion

        #region Properties
            
        /// <summary>
        /// Время прохождения трассы
        /// </summary>
        public TimeSpan? Time
        {
            get { return _time; }
            set
            {
                bool changed = value != _time;
                _time = value;
                if (changed) InvokePropertyChanged(new PropertyChangedEventArgs("Time"));
            }
        } 

        /// <summary>
        /// Тип результата
        /// </summary>
        public RunResultType ResultType
        {
            get { return _resultType; }
            set
            {
                bool changed = value != _resultType;
                _resultType = value;
                if (changed) InvokePropertyChanged(new PropertyChangedEventArgs("ResultType"));
            }
        }

        #endregion

        /// <summary>
        /// Создаёт класс RunResult
        /// </summary>
        /// <param name="time">Время прохождения трассы</param>
        /// <param name="resultType">Тип результата</param>
        public RunResult(TimeSpan? time, RunResultType resultType)
        {
            _time = time;
            _resultType = resultType;
        }

        #region Implementation of INotifyPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;

        public void InvokePropertyChanged(PropertyChangedEventArgs e)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, e);
        }

        #endregion
    }
}
